const path = require("path");
const { defineConfig } = require("@vue/cli-service");
const CompressionPlugin = require("compression-webpack-plugin");
const UglifyJsPlugin = require("uglifyjs-webpack-plugin");
// gzip压缩配置
const compressionOptions = {
    filename: "[path].gz[query]",
    algorithm: "gzip",
    test: /\.(js|css)$/,
    threshold: 10240,
    minRatio: 0.8,
};
// 代码丑化配置
const uglifyJsOptions = {
    uglifyOptions: {
        output: {
            comments: false, // 是否删除注释
        },
        compress: {
            drop_console: true, // 移除console
            drop_debugger: true, // 移除debugger
        },
    },
    sourceMap: false, // 压缩代码最好关闭sourceMap
    parallel: true, // 使用多进程并行运行来提高构建速度
};
module.exports = defineConfig({
    // 输出路径配置
    outputDir: "dist",
    assetsDir: "static",
    filenameHashing: true,
    productionSourceMap: false,
    // 服务代理配置
    devServer: {
        port: 3001,
        open: true,
        proxy: {
            "/api": {
                target: "http://localhost:3000",
                changeOrigin: true,
                pathRewrite: {
                    "^/api": "",
                },
            },
        },
    },
    runtimeCompiler: true,
    lintOnSave: false,
    transpileDependencies: true,
    // 调整内部其他配置：起别名、忽略项、使用插件等
    configureWebpack: {
        resolve: {
            alias: {
                "@": path.join(__dirname, "src"),
            },
        },
        // 忽略项
        externals: {
            // 包名: 在项目中引入的名字,
            // vue: "Vue",
            // "vue-router": "VueRouter",
            // axios: "axios",
        },
        plugins: [
            new CompressionPlugin(compressionOptions),
            new UglifyJsPlugin(uglifyJsOptions),
        ],
        module: {},
    },
    // css相关选项
    css: {
        sourceMap: true,
        loaderOptions: {
            less: {
                lessOptions: {
                    modifyVars: {
                        "primary-color": "#18ffd0", // 修改antd的主题色变量
                    },
                    javascriptEnabled: true,
                },
            },
        },
    },
});
